use cassie_core::config::config::ApplicationConfig;
use cassie_core::config::option::Opt;
use cassie_core::fundation::{AppContext, ApplicationContext};
use clap::Parser;
use tokio::fs::read_to_string;

/**
*description:根据路径初始化系统配置
*author:cassie-lxd<348040933@qq.com>
*/
pub async fn init_config() {
  ApplicationContext::set_service(set_config().await);
}

async fn set_config() -> ApplicationConfig {
  let opt = Opt::parse();
  let config_path = if opt.config_path.is_empty() {
    "bootstrap.toml"
  } else {
    &opt.config_path
  };

  let content = read_to_string(config_path).await.unwrap();
  ApplicationConfig::from_toml(&content)
}